package com.hdu.metrics_center.redisCommand;

import com.hdu.metrics_center.enums.RedisCommandType;
import com.hdu.metrics_center.utils.JedisUtils;
import com.hdu.metrics_center.metrics.MetricsExecuteReq;
import com.hdu.metrics_center.metrics.MetricsExecuteResult;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

import static com.hdu.metrics_center.enums.MetricsQueryResultType.NUM;
@Component
public class HLenRedisCommand implements RedisCommand {
    @Override
    public RedisCommandType support() {
        return RedisCommandType.HLEN;
    }

    @Override
    public MetricsExecuteResult operate(MetricsExecuteReq metricsExecuteReq) {
        Jedis jedis = JedisUtils.getJedis();
        Long hlen = jedis.hlen(metricsExecuteReq.getKey());
        return MetricsExecuteResult
                .builder()
                .type(NUM)
                .value(hlen)
                .reqUuid(metricsExecuteReq.getReqUuid())
                .build();
    }
}
